#include <stdio.h>
#include <stdlib.h>

struct Student // 声明结构体类型struct Student
{
    int num;
    char name[20];
    float score;
};
int compare(const void *a, const void *b) {
    struct Student s1 = *(struct Student *)a;
    struct Student s2 = *(struct Student *)b;
    return -(s1.score - s2.score);
}

int compare2(const void *a, const void *b) {
    struct Student *s1 = (struct Student *)a;
    struct Student *s2 = (struct Student *)b;
    return -(s1->score - s2->score);
}

int main() {
    // 定义结构体数组并初始化
    struct Student stu[5] = {
        {10101, "Zhang", 78},
        {10103, "Wang", 98.5},
        {10106, "Li", 86},
        {10108, "Ling", 73.5},
        {10110, "Sun", 100}
    }; 
    const int n = sizeof(stu) / sizeof(struct Student);
    // 排序
    qsort(stu, n, sizeof(struct Student), compare2);
    // 输出
    for (int i = 0; i < n; i++) {
        printf("%6d %8s %6.2f\n", stu[i].num, stu[i].name, stu[i].score);
    }
    printf("\n");
    return 0;
}
